package com.wing.product.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.common.utils.UniqueIdGeneratorUtil;
import com.wing.product.dao.WarehouseProductionLineDao;
import com.wing.product.model.entity.WarehouseProductionLine;
import com.wing.product.model.response.WarehouseProductionSchedulingPlanVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class WarehouseProductionLineServiceImpl extends ServiceImpl<WarehouseProductionLineDao, WarehouseProductionLine> implements WarehouseProductionLineService{

    @Override
    public Page<WarehouseProductionLine> pageList4app(Page page, Map<String, Object> params) {
        List<WarehouseProductionLine> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    @Transactional
    public JsonResult saveProductionLine(WarehouseProductionLine warehouseProductionLine){

        if (ObjectUtil.isNotEmpty(warehouseProductionLine)){
            if (warehouseProductionLine.getId() != null){
                this.updateById(warehouseProductionLine);
            }else {
                warehouseProductionLine.setProductionLineCode(UniqueIdGeneratorUtil.generateUniqueId("CX", "yyyyMMddHHmmss", 1000, 9999));
                this.baseMapper.insert(warehouseProductionLine);
            }
            return JsonResult.success("操作成功");
        }else {
            return JsonResult.fail("操作失败");
        }
    }

    @Override
    public JsonResult updateStatus(Long id, Integer status){

        WarehouseProductionLine warehouseProductionLine = this.baseMapper.selectById(id);
        warehouseProductionLine.setStatus(status);
        this.updateById(warehouseProductionLine);
        return JsonResult.success("操作成功");
    }
}
